var ExtractTextPlugin = require("extract-text-webpack-plugin");
var webpack = require('webpack');
module.exports = {
	devtool: process.env.NODE_ENV === "production" ?false : "source-map",
	entry: __dirname + "/src/entry/index.js",
	output: {
		path: __dirname + (process.env.NODE_ENV === "production" ? "/build" : "/public"),
		filename: "bundle.js",
		publicPath: '/',
		chunkFilename: '[name].[chunkhash].chunk.js'
	},
	devServer: {
		contentBase: "public/",
		colors: true,
		historyApiFallback: true,
		inline: true,
	},
	module: {
		loaders: [
            {
                test: /\.json$/,
                loader: "json"
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: "babel",
                query: {
                	presets: ['es2015', 'react', 'stage-0']
                }
            },
           {
      		    test: /\.css$/,
     		    loader: ExtractTextPlugin.extract('css?sourceMap&-minimize!' + 'postcss')
   		    },
            {
            	test: /\.(jpe?g|png|gif|svg)$/,
            	loader: 'img!url'
            },
            {
				test:/\.(woff|svg|eot|ttf)\??.*$/,
				/*test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,*/
				loader: 'url'
            }
		]
	},
	postcss: [
        require('autoprefixer')
	],
	plugins: process.env.NODE_ENV === 'production' ? [
    new webpack.optimize.DedupePlugin({
      output: {
        comments: false,

      },
       mangle: {
         except: ['$super', '$', 'exports', 'require', 'module', '_']
       },
      compress: {
        warnings: false,
        screw_ie8: true,
        conditionals: true,
        unused: true,
        comparisons: true,
        sequences: true,
        dead_code: true,
        evaluate: true,
        if_return: true,
        join_vars: true,
      }
    }),
    new webpack.DefinePlugin({
      'process.env': {
          NODE_ENV: JSON.stringify(process.env.NODE_ENV),
      },
    }),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin(),
    new webpack.DllReferencePlugin({
      context: __dirname,
      manifest: require('./build/vendor-manifest.json'),
    }),
    new ExtractTextPlugin("common.css"),
  ] : [
     new ExtractTextPlugin("common.css")
  ]
}
